﻿using Microsoft.SharePoint;
using Repo.Interfaces;

namespace Repo.FieldTypes
{
    public class SPHyperlinkOrPictureField : IComplexFieldType
    {
        public string Value { get; set; }

        public string Url
        {
            get
            {
                    var fieldUrlValue = new SPFieldUrlValue(Value);
                    return fieldUrlValue.Url;
            }
        }

        public string Description
        {
            get
            {
                var fieldUrlValue = new SPFieldUrlValue(Value);
                return fieldUrlValue.Description;
            }
        }

        public IComplexFieldType SetInstanceValue(object value)
        {
            if (value != null)
            {
                return new SPHyperlinkOrPictureField
                {
                    Value = value.ToString()
                };
            }
            return null;
        }
    }
}
